import axios from "axios"

const state = {
    recommendList: [],
    photoList: [],
}

const mutations = {
    RECOMMENDLIST(state, payload) {
        setTimeout(() => {
            state.recommendList = state.recommendList.concat(payload)
        }, 300)
    },
    PHOTOLIST(state, payload) {
        setTimeout(() => {
            // state.photoList = state.photoList.concat(payload)
            // ...扩展运算符
            state.photoList = [...state.photoList, ...payload]
        }, 300)
    },
}

const actions = {

    // 获取新闻
    getRecommendNewsList(store, payload) {
        axios.get("https://api.apiopen.top/getWangYiNews?page="+payload.page+"&count="+payload.count).then(res => {
            if(res.data.code === 200) {
                store.commit("RECOMMENDLIST", res.data.result)
            }
        })
    },

    // 获取美图  stor.commit == {commit}: es6的解构赋值
    getPhotoList({commit}, payload) {
        axios.get("https://api.apiopen.top/getImages?count="+payload.count+"&page="+payload.page).then(res => {
            if(res.data.code === 200) {
                commit("PHOTOLIST", res.data.result)
            }
        })
    },
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
